package com.gin.soul.pojo.graph;

import com.gin.soul.pojo.EdgeEsEnterprisePersonBO;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

/**
 * 图
 * 1.由点的集合和边的集合构成
 * 2.虽然存在有向图和无向图的概念, 但实际上都可以用有向图(无向图有两条有向边)来表达
 * 3.边上可能带有权值
 *
 */
public class Graph {
	//点集, k=编号,v=点的地址
	public HashMap<String, Node> nodes;
	//边集(一定程度冗余, 点集包含了边, 但是利于解决多变的图问题)
	public HashMap<String, List<EdgeEsEnterprisePersonBO>> edges;
	
	public Graph() {
		nodes = new HashMap<>();
		edges = new HashMap<>();
	}

	public Graph(List<EdgeEsEnterprisePersonBO> edgeList) {
		nodes = new HashMap<>();
		edges = new HashMap<>();
		for (EdgeEsEnterprisePersonBO edge : edgeList) {
			List<EdgeEsEnterprisePersonBO> edgeTmpList = null;
			if (edges.get(edge.getSrc()) == null) {
				edgeTmpList = new LinkedList<>();
			} else {
				edgeTmpList = edges.get(edge.getSrc());
			}
			edgeTmpList.add(edge);
			edges.put(edge.getSrc(), edgeTmpList);
		}
	}

}
